const nodemailer = require('nodemailer')

const transport = nodemailer.createTransport({
  pool: true,
  host: 'smtp.qq.com',
  port: 465,
  secure: true, // use TLS
  secureConnection: true, // use SSL
  auth: {
    user: '2038174431@qq.com',
    pass: 'jecukydigwcobgjd',
  },
})


function sendMail(options) {
  return new Promise((resolve, reject) => {
    transport.sendMail(options, (err, info) => {
      if (err) {
        reject(err)
      } else {
        resolve(info)
      }
    })
  }).catch(err => err)
}

function registerConfig(email, authcode) {
  return {
    from: '"Leazer Fspace" <2038174431@qq.com>',
    to: email,
    subject: "Leazer Fspace 验证注册账户",
    html: `<div style="padding:40px 30px;background-color:#01579B;color:#eee;border-radius:3px;">
            <h2>欢迎注册Leazer Fspace，我们将给您最优质的会议体验！</h2>
            <h2>您的验证码为：<span style="font-size:32px;">${authcode}</span></h2>
          </div>`
  }
}

function resetConfig(email, authcode) {
  return {
    from: '"Leazer Fspace" <2038174431@qq.com>',
    to: email,
    subject: "Leazer Fspace 重置密码",
    html: `<div style="padding:40px 30px;background-color:#01579B;color:#eee;border-radius:3px;">
            <h2>您的验证码为：<span style="font-size:32px;">${authcode}</span></h2>
          </div>`
  }
}

module.exports = {
  sendMail: sendMail,
  registerConfig: registerConfig,
  resetConfig: resetConfig
}